<template>
  <p-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel">
    <p-spin :spinning="confirmLoading">
      <!-- 主表单区域 -->
      <p-form :form="form">
        <p-row>

	  <p-col :span="12">
		<p-form-item label="产品编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
			<f-popup
					contextPath="basic-business"
					v-decorator="['mcode', validatorRules.mcode]"
					:trigger-change="true"
					org-fields="id,mcode,mname,sprc,mexplain"
					dest-fields="mid,mcode,mname,sprc,mexplain"
					code="wms_cpinfo"
					@callback="popupCallback"/>
		</p-form-item>
      </p-col>
	  <p-col :span="12">
		<p-form-item label="产品名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
			<p-input readOnly  v-decorator="[ 'mname', validatorRules.mname]" placeholder="请输入产品名称"></p-input>
		</p-form-item>
      </p-col>
	  <p-col :span="12">
		<p-form-item label="产品规格型号" :labelCol="labelCol" :wrapperCol="wrapperCol">
			<p-input readOnly  v-decorator="[ 'sprc', validatorRules.sprc]" placeholder="请输入产品规格型号"></p-input>
		</p-form-item>
      </p-col>
	  <p-col :span="12">
		<p-form-item label="产品描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
			<p-input readOnly  v-decorator="[ 'mexplain', validatorRules.mexplain]" placeholder="请输入产品描述"></p-input>
		</p-form-item>
      </p-col>
	  <p-col :span="12">
		<p-form-item label="产品系列" :labelCol="labelCol" :wrapperCol="wrapperCol">
			<p-input   v-decorator="[ 'productLine', validatorRules.productLine]" placeholder="请输入产品系列"></p-input>
		</p-form-item>
      </p-col>
	  <p-col :span="12">
		<p-form-item label="审核" :labelCol="labelCol" :wrapperCol="wrapperCol">
			<j-dict-select-tag  type="list" v-decorator="['processPt', validatorRules.processPt]" :trigger-change="true" dictCode="mes_checkflg" placeholder="请选择审核"/>
		</p-form-item>
      </p-col>
	  <p-col :span="12">
		<p-form-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
			<j-dict-select-tag  type="radio" v-decorator="['processStatus', validatorRules.processStatus]" :trigger-change="true" dictCode="open_close" placeholder="请选择状态"/>
		</p-form-item>
      </p-col>

        </p-row>
      </p-form>

      <!-- 子表单区域 -->
      <p-tabs v-model="activeKey" @change="handleChangeTabs">
        <p-tab-pane tab="基础信息工艺路线" :key="refKeys[0]" :forceRender="true">
          <j-editable-table
            :ref="refKeys[0]"
            :loading="mesPeProductProcessRouteTable.loading"
            :columns="mesPeProductProcessRouteTable.columns"
            :dataSource="mesPeProductProcessRouteTable.dataSource"
            :maxHeight="300"
            :rowNumber="true"
            :rowSelection="true"
            :actionButton="true"/>
        </p-tab-pane>
        
      </p-tabs>

    </p-spin>
  </p-modal>
</template>

<script>

  import pick from 'lodash.pick'
  import { FormTypes,getRefPromise } from '@/utils/JEditableTableUtil'
  import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
  import { validateDuplicateValue } from '@/utils/util'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: 'MesPeProcessMaterialBasisModal',
    mixins: [JEditableTableMixin],
    components: {
      JDictSelectTag,
    },
    data() {
      return {
        labelCol: {
          span: 6
        },
        wrapperCol: {
          span: 16
        },
        labelCol2: {
          span: 3
        },
        wrapperCol2: {
          span: 20
        },
        // 新增时子表默认添加几行空数据
        addDefaultRowNum: 1,
        validatorRules: {
          mcode: {rules: [
            {required: true, message: '请输入产品编码!'},
          ]},
          mname: {rules: [
          ]},
          sprc: {rules: [
          ]},
          mexplain: {rules: [
          ]},
          productLine: {rules: [
          ]},
          processPt: {rules: [
          ]},
          processStatus: {rules: [
          ]},
        },
        refKeys: ['mesPeProductProcessRoute', ],
        tableKeys:['mesPeProductProcessRoute', ],
        activeKey: 'mesPeProductProcessRoute',
        // 基础信息工艺路线
        mesPeProductProcessRouteTable: {
          loading: false,
          dataSource: [],
          columns: [
            {
              title: '产品系列',
              key: 'productLine',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '工艺路线内码',
              key: 'processid',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '工艺路线编码',
              key: 'processCoding',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '工艺路线名称',
              key: 'processName',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '工艺路线类型',
              key: 'processType',
              type: FormTypes.select,
              dictCode: '',
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
          ]
        },
        url: {
          add: '/mes-craft/auto/mesPeProcessMaterialBasis/add',
          edit: '/mes-craft/auto/mesPeProcessMaterialBasis/edit',
          mesPeProductProcessRoute: {
            list: '/mes-craft/auto/mesPeProcessMaterialBasis/queryMesPeProductProcessRouteByMainId'
          },
        }
      }
    },
    methods: {
      getAllTable() {
        let values = this.tableKeys.map(key => getRefPromise(this, key))
        return Promise.all(values)
      },
      /** 调用完edit()方法之后会自动调用此方法 */
      editAfter() {
        let fieldval = pick(this.model,'mcode','mname','sprc','mexplain','productLine','version','processPt','processStatus')
        this.$nextTick(() => {
          this.form.setFieldsValue(fieldval)
        })
        // 加载子表数据
        if (this.model.id) {
          let params = { id: this.model.id }
          this.requestSubTableData(this.url.mesPeProductProcessRoute.list, params, this.mesPeProductProcessRouteTable)
        }
      },
      /** 整理成formData */
      classifyIntoFormData(allValues) {
        let main = Object.assign(this.model, allValues.formValue)

        return {
          ...main, // 展开
          mesPeProductProcessRouteList: allValues.tablesValue[0].values,
        }
      },
      validateError(msg){
        this.$message.error(msg)
      },
     popupCallback(row){
       this.form.setFieldsValue(pick(row,'mcode','mname','sprc','mexplain','productLine','version','processPt','processStatus'))
     },

    }
  }
</script>

<style scoped>
</style>